package com.bytedance.lucky.http;

import lombok.Data;

import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 请求公共数据解析
 *
 * @author zouyaowen
 * @date 2021-02-12 22:08
 */
public class RequestHolder {

    private final static ThreadLocal<RequestInfo> REQUEST_INFO_THREAD_LOCAL = new ThreadLocal<>();

    public static void setRequestInfo(RequestInfo requestInfo) {
        REQUEST_INFO_THREAD_LOCAL.set(requestInfo);
    }

    public static Optional<RequestInfo> getRequestInfo() {
        return Optional.ofNullable(REQUEST_INFO_THREAD_LOCAL.get());
    }

    public static void removeRequestInfo() {
        REQUEST_INFO_THREAD_LOCAL.remove();
    }

    @Data
    public static class RequestInfo {
        private LocalDateTime qt;
        private String uri;
        private String method;
    }

}
